import time

from selenium import webdriver
import os
import pytest
import allure
import yaml
from page.login import Login
from selenium.webdriver.common.by import By
from tools.tools import Tools

@allure.feature('代理商模块')
class TestAgent:
    @pytest.fixture(scope='class',autouse=True)
    def classsetup(self):
        """
        类级别初始化
        :return:
        """
        yield

    @pytest.fixture(autouse=True)
    def methodestupteardown(self):
        """
        方法初始化
        :return:
        """
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        self.po = Login(self.driver)
        self.logger = Tools().get_logger("Test.Login")
        yield
        time.sleep(2)
        self.driver.quit()


    @allure.story('登录')
    @pytest.mark.parametrize("username, password, msg",yaml.safe_load(open('E:\Django\DjangoProject\hubanghuzhu\Data\data.yaml', 'r', encoding='utf-8')))
    def test_forward(self,username,password,msg):
        """登录到代理商的公共操作"""
        with allure.step('登录'):
            self.logger.info('执行前置操作：登录')
            self.po.login_success(username,password)
            dy = self.po.find_element((By.XPATH,'/html/body/div[2]')).text
            assert msg == dy,f'断言失败,实际值{dy}'
            self.logger.info(f'登录成功:{dy}')




if __name__ == '__main__':
    #生成Allure原始数据
    pytest.main(['./Case','-v','--alluredir=./report/allure_raw'])

    #生成HTML报告
    os.system('allure generate ./report/allure_raw -o ./report/allure_html --clean')
    os.system('allure open ./report/allure_html')